package star.cloud.asme.system.role;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import star.cloud.asme.base.dto.Result;
import star.cloud.asme.base.mybatis.IBaseController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/system/role")
public class RoleController implements IBaseController<Role> {

    private final RoleService roleService;

    @Override
    public Result<Role> getOneByCondition(String columnName, Object columnValue) {
        return roleService.getOneByCondition(columnName, columnValue);
    }

    @Override
    public Result<IPage<Role>> getListByConditionsWithPage(Role entity) {
        return roleService.getListByConditionsWithPage(entity);
    }

    @Override
    public Result<List<Role>> getListByConditions(Role entity) {
        return roleService.getListByConditions(entity);
    }

    @Override
    @PreAuthorize("hasRole('超级管理员')")
    public Result<Role> insertOne(Role entity) {
        return roleService.insertOne(entity);
    }

    @Override
    @PreAuthorize("hasRole('超级管理员')")
    public Result<?> physicalDeleteById(Long id) {
        return roleService.physicalDeleteById(id);
    }

    @Override
    @PreAuthorize("hasRole('超级管理员')")
    public Result<?> logicalDeleteById(@PathVariable("id") Long id) {
        return roleService.logicalDeleteById(id);
    }

    @Override
    @PreAuthorize("hasRole('超级管理员')")
    public Result<Role> updateOne(Role entity) {
        return roleService.updateOne(entity);
    }

    @PostMapping("/setRoleIdByUserId")
    public Result<?> setRoleIdByUserId(RoleDTO roleDTO) {
        return roleService.setRoleIdByUserId(roleDTO);
    }
}